(function ($) {
    $.schoolCourses = function () {
        return {
            init: function () {
                this.listener();
                this.initLayui();
                this.resize();
                this.periodInfoGet();
            },
            /**
             * 添加各按钮所需要的监听事件
             */
            listener: function () {
                /**
                 *点击 我的课程 课程资源
                 * **/
                $(".schoolType li").on("click", function () {
                    var html = "";
                    var navHtml = "";
                    if ($(this).attr("data-type") == "1") {
                        html += '<li data-href="courseList.html" class="active">课件列表</li>'
                            + '<li data-href="topicList.html">题目列表</li>'
                            + '<li data-href="periodAction.html">学段管理</li>';
                        navHtml += '<a>校内课程</a>'
                            + '<a data-href="courseList.html">课件列表</a>';
                        $("#schoolCoursesRight").attr("src", "courseList.html");
                    } else {
                        html += '<li data-href="courseResource.html" class="active">课程资源</li>';
                        navHtml += '<a>校内课程</a>'
                            + '<a data-href="courseResource.html">课程资源</a>';
                        $("#schoolCoursesRight").attr("src", "courseResource.html");
                    }
                    $("#schoolCoursesLeft").html(html);
                    $(".breadcrumb .layui-breadcrumb").html(navHtml);
                    $.schoolCourses.initLayui();
                });
                /**
                 *点击侧边栏选择文件类型
                 * **/
                $("#schoolCoursesLeft").on("click", "li", function () {
                    $(this).siblings(".active").removeClass("active");
                    $(this).addClass("active");
                    $("#schoolCoursesRight").attr("src", $(this).attr("data-href"));
                    var navHtml = "";
                    navHtml += '<a>校内课程</a>'
                        + '<a data-href=' + $(this).attr("data-href") + '>' + $(this).html() + '</a>';
                    $(".layui-breadcrumb").html(navHtml);
                    $.schoolCourses.initLayui();
                });
                /**
                 *点击导航栏进行页面跳转
                 * **/
                $(".breadcrumb .layui-breadcrumb").on("click", "a:not(:first-child,:last-child)", function () {
                    $("#schoolCoursesRight").attr("src", $(this).attr("data-href"));
                    //删除多余的链接
                    $(this).nextAll().remove();
                    $(this).find(".layui-box").remove();
                });

                /**
                 *页面调整
                 * **/
                $(window).resize($.schoolCourses.resize);
            },
            periodInfoGet: function () {
                var periodInfoGet={token:User.token};
                updateObject(Doman.url + Doman.xnPeriodInfoGet, false, JSON.stringify(periodInfoGet), function (result) {
                    if (result.code != "200") {
                        layui.use(['layer', 'form', 'element'], function () {
                            $ = layui.jquery, layer = layui.layer, element = layui.element, form = layui.form;
                            //页面层
                            layer.open({
                                type: 2,
                                title: '请选择您的教学课程范围',
                                closeBtn: 0,
                                shadeClose: false, //开启遮罩关闭
                                area: ['1024px', window.innerHeight - 100 + "px"], //宽高
                                content: "pageFrame/periodInfoSet.html"
                            });
                        });
                    }
                }, function () {
                });
            },
            /**
             * 页面设置高度
             * **/
            resize: function () {
                $("#schoolCoursesLeft,#schoolCoursesRight").css("height", window.innerHeight - 85 + "px");
            },

            initLayui: function () {
                layui.use(['layer', 'form', 'element'], function () {
                    $ = layui.jquery, layer = layui.layer, element = layui.element, form = layui.form;
                    element.init();
                });
            }
        }
    }();
    $.schoolCourses.init();
})(jQuery);